
function prefsSet(name, val) {
  localStorage["options."+name] = val;
}
function prefsSetJSON(name, val) {
  localStorage["options." + name] = JSON.stringify(val);
}
function prefsGetInt(name, dflt) {
  var val = localStorage["options." + name];
  var ret;
  try {
    ret = parseInt(val);
    if (isFinite(ret)) {
      return ret;
    }
  } catch(e) {
  }
  return dflt;
}
function prefsGetBool(name, dflt) {
  var val = localStorage["options."+name];
  if ("true"==val)  return true;
  if ("false"==val)  return false;
  return dflt;
}
function prefsGetString(name, dflt) {
  var val = localStorage["options."+name];
  if (undefined==val || null==val)  return dflt;
  return val;
}
function prefsGetJSON(name, dflt) {
  var val = localStorage["options."+name];
  try {
    ret = JSON.parse(val);
  } catch(e) {
    ret = dflt;
  }
  return ret;
}

